/* 
 * Serhiy Bondarenko
 * Task 4. Calendar Seeker
 */
import java.util.*;
	
/**
 * Class CalendarSeeker prints to the screen the 
 * day of the week for a inputted day, month and year.
 * @version 1.2 28 Jan 2013
 * @author Serhiy Bondarenko
 */
public class CalendarSeeker {

public static void main(String args[]) {
    int[] inputtedDate;
    inputtedDate = inputDate();
    int numberOfDay;
    numberOfDay = calculateDayOfWeek(inputtedDate);
    printDayOfWeek(numberOfDay);
}  

private static int inputByKeyboard(String elementOfDate) {
    System.out.println("Enter the number of " + elementOfDate);
    return new Scanner(System.in).nextInt();
}

/**
 * Method toInputDate()
 * @return int[] array with inputted date
 */
private static int[] inputDate() {
    int day;
    int month;
    int year;
    day = inputByKeyboard("day");
    month = inputByKeyboard("month");
    year = inputByKeyboard("year");
    return new int[] {day, month, year};
}

/**
 * Method toCalculateDayOfWeek() get information about inputted date in array form [day, month, year]
 * and return index of day of week- integer number of range [0;6]
 * Source - http://ru.wikibooks.org/wiki
 * @param date - int[] array with inputted date
 * @return indexOfDayOfWeek - int number of range [0;6]
 */
private static int calculateDayOfWeek(int[] date) {
    int ofset = (14 - date[1]) / 12;
    int monthConsideredOfset = date[1] + 12 * ofset - 2;
    int yearConsideredOfset = (date[2] + 1) - ofset;
    int indexOfDayOfWeek = (6999 + date[0] + yearConsideredOfset + yearConsideredOfset / 4
	                   - yearConsideredOfset / 100 + yearConsideredOfset / 400 
                       + (31 * monthConsideredOfset) / 12) % 7;
    return indexOfDayOfWeek;
}

private static void printDayOfWeek(int numberOfDay) {
    String[] daysOfWeek = {"Sunday", "Monday", "Tuesday", "Wednesday",
	                       "Thursday", "Friday", "Saturday"};
    System.out.println(daysOfWeek[numberOfDay]);	
}

}